#include <typedef.h>
//
#include <mission_run.hpp>

class Eg1Mission : public Mission
{
public:
	Eg1Mission(int timeoutMs, int timeoutOpt)
		: Mission(timeoutMs, timeoutOpt)
	{
	}

	virtual ~Eg1Mission()
	{
	}

	void RunImplNormal(void* arg)
	{
		if (m_UserData == 0)
		{
			LOG("mission eg1 mis run A.\n");
			m_UserData++;
		}
		else if (m_UserData < 30)
		{
			m_UserData++;
		}
		else if (m_UserData == 30)
		{
			LOG("mission eg1 mis run B.\n");
			Finish();
		}
	}

	void RunImplStopped(void* arg)
	{
		LOG("mission eg1 Stopped.\n");
	}

	void RunImplTimeout(void* arg)
	{
		LOG("mission eg1 Timeout.\n");
	}
};

class Eg2Mission : public Mission
{
public:
	Eg2Mission(int timeoutMs, int timeoutOpt)
		: Mission(timeoutMs, timeoutOpt)
	{
	}

	virtual ~Eg2Mission()
	{
	}

	void RunImplNormal(void* arg)
	{
		if (m_UserData == 0)
		{
			LOG("mission eg2 mis run A.\n");
			m_UserData++;
		}
		else if (m_UserData < 30)
		{
			m_UserData++;
		}
		else if (m_UserData == 30)
		{
			LOG("mission eg2 mis run B.\n");
			Finish();
		}
	}

	void RunImplStopped(void* arg)
	{
		LOG("mission eg2 Stopped.\n");
	}

	void RunImplTimeout(void* arg)
	{
		LOG("mission eg2 Timeout.\n");
	}
};


/* @RegistMainFunction */
int mis_eg_main(int argc, char** argv)
{
	if (argc == 2 && strcmp(argv[1], "test") == 0)
	{
		Eg1Mission* eg1 = new Eg1Mission(30000, 1);
		Eg2Mission* eg2 = new Eg2Mission(30000, 1);

		MissionList* misList = new MissionList();
		misList->Append(eg1);
		misList->Append(eg2);

		MissionRun::Instance()->Create(misList);

		return 0;
	}

	return -1;
}